
cap log close
log using "Singapore Price Rent (Table A6)", replace

use "D:\Housing Term Structure\Singapore Data\Listings\iPropertySG-listings.dta", clear

gen log_price = log(price)
destring(district), replace force

* Controls
gen quarter_new = qofd(date_new)
gen year        = year(date_new)
gen month       = mofd(date_new)

egen kgroup       = group(kitchen)
egen tenid        = group(tenureid)
egen prop_type    = group(protype)
egen prog_type    = group(progrtype)
egen level_group  = group(level)
egen storey_group = group(storey)

egen fe_1 = group(quarter  district)
egen fe_2 = group(quarter  postalcode)
egen fe_3 = group(month    postalcode)
egen fe_4 = group(month    postalcode bedrooms)

egen    size_group = cut(size), group(50)
egen    age_group  = group(age)

winsor log_price, gen(lp1) p(0.01)

duplicates tag lp1 prop_type bedrooms bath size_group age_group kgroup tenid storey_group prog_type level_group for_rent year, gen(dup1)

areg lp1 																												  for_rent if year == 2012 & dup1 ==0, absorb(fe_2) cluster(fe_2)
eststo Col1
areg lp1 i.prop_type i.bedrooms i.bath i.age_group i.size_group i.kgroup i.tenid i.storey_group i.prog_type i.level_group for_rent if year == 2012 & dup1 ==0, absorb(fe_2) cluster(fe_2)
eststo Col2
areg lp1 i.prop_type i.bedrooms i.bath i.age_group i.size_group i.kgroup i.tenid i.storey_group i.prog_type i.level_group for_rent if year == 2012 & dup1 ==0, absorb(fe_3) cluster(fe_3)
eststo Col3
areg lp1 i.prop_type i.bedrooms i.bath i.age_group i.size_group i.kgroup i.tenid i.storey_group i.prog_type i.level_group for_rent if year == 2012 & dup1 ==0, absorb(fe_4) cluster(fe_4)
eststo Col4

esttab Col1 Col2 Col3 Col4 using "Table RP.tex", ///
	   replace width(\hsize) nocon b(3) se(3) title(Rent-Price Ratio Singapore 2012) sty(tex) stats(r2_a ymean N, labels(R-squared MeanDepVar N)) ///
	   noconstant star(* 0.10 ** 0.05 *** 0.01) label ///
	   keep(for_rent)
	   
cap log close	   
